from alipay import AliPay, AliPayConfig
from fastapi import APIRouter, Depends, HTTPException,status
from sqlalchemy import select, update
import aiofiles

import settings
from models.order import Order
from models.seckill import *
from datetime import datetime
from schemas.response import OrderListSchema, OrderSchema
from hooks.dependencies import get_db_session
from models import AsyncSession
from utils.auth import AuthHandler
from schemas.request import BuySchema
auth_handler = AuthHandler()
router = APIRouter()

@router.get('/list', response_model=OrderListSchema)
async def get_order_list(page:int=1, size:int=10,
                         user_id:int=Depends(auth_handler.auth_access_dependency),session:AsyncSession=Depends(get_db_session)):
    async with session.begin():
        result = await session.execute(select(Order).where(Order.user_id==user_id).order_by(Order.id.desc()).offset((page-1)*size).limit(size))
        orders = result.scalars().all()
    return {"orders":orders}